package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.jd.JdPgScore;
import com.ucredit.babel.common.model.third.jd.JdPgScoreData;
import com.ucredit.babel.common.model.third.jd.JdPgScoreRecord;
import com.ucredit.babel.common.model.third.pudao.PuDaoPanGuThreeElementData;
import com.ucredit.babel.common.model.third.pudao.PuDaoPanGuThreeElementRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;
import java.io.IOException;

/**
 *
 * 京东盘古V3分&指标
 *
 * @author renzhanzheng
 */


public class JdPgScoreParse extends ParseBase{
    private Text val = new Text();
    private Text key = new Text();

    /**
     *
     * 京东盘古V3分&指标
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        PuDaoPanGuThreeElementRecord obj = (PuDaoPanGuThreeElementRecord)model;
        PuDaoPanGuThreeElementData data = obj.getData() == null ? new PuDaoPanGuThreeElementData() : obj.getData();
        JdPgScore scoreData = data.getData() == null ? new JdPgScore() : data.getData();

        StringBuilder sb = getBaseInfo(obj, successful);

        //返回编码
        sb.append(data.getCode() == null ? "" : data.getCode()).append(CRT001);
        //返回信息
        sb.append(data.getMsg()== null ? "" : data.getMsg()).append(CRT001);
        //盘古分v3（三要素）
        sb.append(scoreData.getScore() == null ? "" : scoreData.getScore()).append(CRT001);
        //稳定性
        sb.append(scoreData.getStability() == null ? "" : scoreData.getStability()).append(CRT001);
        //购买力指数
        sb.append(scoreData.getBuyingIndex() == null ? "" : scoreData.getBuyingIndex()).append(CRT001);
        //交易风险指数
        sb.append(scoreData.getRiskIndex() == null ? "" : scoreData.getRiskIndex()).append(CRT001);
        //履约指数
        sb.append(scoreData.getPerformanceIndex() == null ? "" : scoreData.getPerformanceIndex()).append(CRT001);
        //理性消费指数
        sb.append(scoreData.getResonableConsuming() == null ? "" : scoreData.getResonableConsuming()).append(CRT001);
        //常驻城市
        sb.append(scoreData.getCity() == null ? "" : scoreData.getCity()).append(CRT001);
        //消费社交影响力
        sb.append(scoreData.getComsumingSocial() == null ? "" : scoreData.getComsumingSocial()).append(CRT001);
        //收入水平
        sb.append(scoreData.getIncomming() == null ? "" : scoreData.getIncomming()).append(CRT001);
        //高危时段消费指数
        sb.append(scoreData.getRiskPeriodConsuming() == null ? "" : scoreData.getRiskPeriodConsuming()).append(CRT001);
        //高危品类消费指数
        sb.append(scoreData.getRiskCategoryConsuming() == null ? "" : scoreData.getRiskCategoryConsuming()).append(CRT001);
        //工作时间网购偏好
        sb.append(scoreData.getWorktimeShopping() == null ? "" : scoreData.getWorktimeShopping()).append(CRT001);
        //手机依赖度
        sb.append(scoreData.getCellphonePreference() == null ? "" : scoreData.getCellphonePreference()).append(CRT001);
        //电商活跃度
        sb.append(scoreData.getEcommerceActiveness() == null ? "" : scoreData.getEcommerceActiveness()).append(CRT001);
        //电商收货地址稳定性
        sb.append(scoreData.getEcommerceAddressStability() == null ? "" : scoreData.getEcommerceAddressStability()).append(CRT001);
        //电商联系方式稳定性
        sb.append(scoreData.getEcommercecellphoneStability() == null ? "" : scoreData.getEcommercecellphoneStability()).append(CRT001);
        //电商账龄等级
        sb.append(scoreData.getEcommerceAccountHistory() == null ? "" : scoreData.getEcommerceAccountHistory()).append(CRT001);

        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb.toString()).replace("\n","").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_jingdong_panguv3score_inc";
    }

    @Override
    public String getType() {
        return RecordType.PD_PANGU_THREE_ELEMENT_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "朴道京东盘古V3分&指标";
    }
}
